<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="stylesheet" href="../../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="" lay-filter="form-filter">
	<div class="mainBox">
		<div class="main-container">
			<div class="layui-form-item layui-hide">
				<label class="layui-form-label required">ID</label>
				<div class="layui-input-block">
					<input type="text" name="id" class="layui-input" disabled>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label required">套餐名称</label>
				<div class="layui-input-block">
					<input type="text" name="name" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label required">套餐类型</label>
				<div class="layui-input-block">
					<select name="type" lay-verify="required"></select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label required">原价</label>
				<div class="layui-input-block">
					<input type="number" name="originalPrice" required lay-verify="required" value="0" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label required">销售价</label>
				<div class="layui-input-block">
					<input type="number" name="salePrice" required lay-verify="required" value="0" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">成本价</label>
				<div class="layui-input-block">
					<input type="number" name="costPrice" value="" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label required">排序号</label>
				<div class="layui-input-block">
					<input type="number" name="sort" required lay-verify="required" value="0" placeholder="" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
	</div>
	<div class="bottom">
		<div class="button-container">
			<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="submit-filter">
				<i class="layui-icon layui-icon-ok"></i>提交
			</button>
			<button type="reset" class="pear-btn pear-btn-sm">
				<i class="layui-icon layui-icon-refresh"></i>重置
			</button>
		</div>
	</div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
	layui.use(['form', 'jquery', 'vtlForm'], function() {
		let form = layui.form;
		let $ = layui.jquery;
		let vtlForm = layui.vtlForm;
		let url = layui.url();
		let id = url.search.id;

		form.on('submit(submit-filter)', function(data) {
			if(id) {
				$.put('/crm/course-package/update', JSON.stringify(data.field), function(result) {
					if (result.code == 0) {
						$.vtl.closeLayer();
						parent.refresh();
					}
				});
			} else {
				$.post('/crm/course-package/create', JSON.stringify(data.field), function(result) {
					if (result.code == 0) {
						$.vtl.closeLayer();
						parent.refresh();
					}
				});
			}

			return false;
		});

		window.init = function(id) {
			vtlForm.initSelectByDict('form select[name=type]', 'crm_course_package_type');

			if(id) {
				$.get('/crm/course-package/get?id=' + id, function(result) {
					form.val("form-filter", result.data);
				});
			}

		}

		window.init(id);
	})
</script>
</body>
</html>
